package cn.lili.modules.payment.serviceimpl;

import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.order.order.entity.dto.OrderSearchParams;
import cn.lili.modules.payment.entity.dos.UserFPointsHistory;
import cn.lili.mybatis.util.PageUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.lili.modules.payment.service.LiUserFpointHistoryService;
import cn.lili.modules.payment.mapper.LiUserFpointHistoryMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
* @author asus
* @description 针对表【li_user_fpoint_history(会员F分记录表)】的数据库操作Service实现
* @createDate 2023-10-09 16:03:04
*/
@Service
public class LiUserFpointHistoryServiceImpl extends ServiceImpl<LiUserFpointHistoryMapper, UserFPointsHistory>
    implements LiUserFpointHistoryService{


    @Override
    public ResultMessage<Page<UserFPointsHistory>> fpointsPage(OrderSearchParams searchParams) {
        AuthUser currentUser = UserContext.getCurrentUser();
        if (currentUser == null) {
            return ResultUtil.error(500,"登录已过期");
        }
        LambdaQueryWrapper<UserFPointsHistory> historyLambdaQueryWrapper = new LambdaQueryWrapper<>();
        historyLambdaQueryWrapper.eq(UserFPointsHistory::getMemberId, currentUser.getExtendId());
        historyLambdaQueryWrapper.orderByDesc(UserFPointsHistory::getCreateTime);
        Page<UserFPointsHistory> pointsHistoryPage = this.page(PageUtil.initPage(searchParams), historyLambdaQueryWrapper);
        return ResultUtil.data(pointsHistoryPage);
    }

}




